package com.hotau.util;


import android.content.Context;
import android.content.SharedPreferences;


public class SaveLoginInfoUtil{
	public static final String PREFS_NAME = "MyFile";
	
	
	public static void save(String accountType,String account,Context context) {
		// 在指定配置文件中配置
		SharedPreferences settings = context.getSharedPreferences(PREFS_NAME,
				Context.MODE_PRIVATE);
		SharedPreferences.Editor editor = settings.edit();
		editor.putString("accountType", accountType);
		editor.putString("cardNo", account);
		editor.commit();
		
	}
	public static void saveMember(boolean isMember,Context context){
		SharedPreferences settings = context.getSharedPreferences(PREFS_NAME,
				Context.MODE_PRIVATE);
		SharedPreferences.Editor editor = settings.edit();
		editor.putBoolean("isMember", isMember);
		editor.commit();
	}
	
	public static void saveCardNoUserName(String cardNumber,String userName,Context context) {
		// 在指定配置文件中配置
		SharedPreferences settings = context.getSharedPreferences(PREFS_NAME,
				Context.MODE_PRIVATE);
		SharedPreferences.Editor editor = settings.edit();
		editor.putString("cardNumber", cardNumber);
		editor.putString("userName", userName);
		editor.commit();
		
	}
	
	
	public static String getCardNo(Context context){
		
		SharedPreferences settings = context.getSharedPreferences(PREFS_NAME,
				Context.MODE_PRIVATE);
		String carNo = settings.getString("cardNumber", "");
		
		return carNo;
	}
	
	
	public static void saveB2cName(String b2cname,Context context) {
		// 在指定配置文件中配置
		SharedPreferences settings = context.getSharedPreferences(PREFS_NAME,
				Context.MODE_PRIVATE);
		SharedPreferences.Editor editor = settings.edit();
		editor.putString("b2cname", b2cname);
		
		editor.commit();
		
	}
	
	
	public static String getB2CName(Context context){
		
		SharedPreferences settings = context.getSharedPreferences(PREFS_NAME,
				Context.MODE_PRIVATE);
		String b2cname = settings.getString("b2cname", "");
		
		return b2cname;
	}
	
	
	public static boolean isLogin(Context context){
		boolean flag = false;
		SharedPreferences settings = context.getSharedPreferences(PREFS_NAME,
				Context.MODE_PRIVATE);
		String carNo = settings.getString("cardNo", "");
		if(carNo!=null && !carNo.equals("")){
			flag=true;
		}
		return flag;
	}
	
	public static void logout(Context context){
		boolean flag = false;
		SharedPreferences settings = context.getSharedPreferences(PREFS_NAME,
				Context.MODE_PRIVATE);
		String carNo = settings.getString("cardNo", "");
		carNo=null;
		SharedPreferences.Editor editor = settings.edit();
		editor.putString("cardNo", carNo);
		editor.putString("cardNumber", "");
		editor.putString("userName", "");
		editor.putBoolean("isMember", true);
		editor.commit();

	}
	
	public static boolean isMember(Context context){
		SharedPreferences settings = context.getSharedPreferences(PREFS_NAME,
				Context.MODE_PRIVATE);
		boolean isMember = settings.getBoolean("isMember", true);
		
		return isMember;
	}
	public static String getCardNumber(Context context) {
		SharedPreferences settings = context.getSharedPreferences(PREFS_NAME,
				Context.MODE_PRIVATE);
		String cardNumber = settings.getString("cardNumber", "");
		
		return cardNumber;
		
	}
	
	public static String getUseName(Context context) {
		SharedPreferences settings = context.getSharedPreferences(PREFS_NAME,
				Context.MODE_PRIVATE);
		String userName = settings.getString("userName", "");
		
		return userName;
		
	}
	
}
